package day240509.p2;

import day240423.work.MyEmailUtil;
import jakarta.mail.MessageRemovedException;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class JsoupDuotai {
    public static void printInfo(int page,String target,JieXi jieXi) throws Exception {
        Elements es=new Elements();
        String msg="";
        for (int i = 0; i <page ; i++) {
            es.addAll(jieXi.getInfo(i+1));
        }
        for (Element e:es){
            System.out.println(e.text());
        }
        //关键词命中
        System.out.println("===== 以下是包含"+target+"关键词的" );
        for (int i = 0; i <es.size() ; i++) {
            if (es.get(i).text().contains(target)){
//                System.out.println("标题：" + es.get(i).text() + "\n链接： https://bbs2.xmfish.com/" + es.get(i).attr("href"));
                msg+= "标题：" + es.get(i).text() + "<br>" +
                        "链接： "+jieXi.setLink() + es.get(i).attr("href") + "<br>";
            }
            if (!msg.equals("")){
                MyEmailUtil.send("2084281579@qq.com", msg);
            }

        }
    }
}
